package com.easy_buy.service;


import com.easy_buy.core.Result;
import com.easy_buy.domain.Role;
import com.easy_buy.repository.SupRepository;
import com.easy_buy.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CheckService {
    @Autowired
    private SupRepository supRepository;
    @Autowired
    private UserRepository userRepository;

    public Result check(String code, String password) {
        // 1、先查供应商表
        Role role = supRepository.findByScode(code);
        // 2、没有数据，查用户表
        if (role == null) {
            role = userRepository.findByUcode(code);
        }

        Result result = new Result();

        if (role == null) {
            result.setCode(404);
            result.setMsg("用户不存在！");
        } else {
            if (!password.equals(role.getPassword())) {
                result.setCode(403);
                result.setMsg("密码错！");
            } else {
                result.setCode(200);
                result.setMsg("验证通过");
                result.setData(role);
            }
        }
        return result;
    }

}
